package com.muhan.ssm.config;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.springframework.core.convert.converter.Converter;

/**
 * 时间转换器
 * @author muhan
 *
 */
public class DateConverter implements Converter<String,Date>{
	
	private String datePattern = "yyyy-MM-dd HH:mm:ss";
	//格式化日期
	public Date convert(String source) {
		SimpleDateFormat format = new SimpleDateFormat(datePattern); 
		try {
			return  format.parse(source);
		} catch (ParseException e) {
			throw new IllegalArgumentException("无效日期格式,请使用:"+datePattern);
		}
	}

}
